package com.maolong.topic;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class TopicProductor {
    private static final String EXCHANGE_NAME = "topic_exchange";
    private static final String QUEUE_NAME = "topic_queue_1";
    private static final String QUEUE_NAME2 = "topic_queue_2";

    public static void main(String[] args) throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("182.92.151.172");
        factory.setUsername("maolong");
        factory.setPassword("123456");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.exchangeDeclare(EXCHANGE_NAME, "topic");
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        channel.queueDeclare(QUEUE_NAME2, false, false, false, null);

        channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, "info.*");
        channel.queueBind(QUEUE_NAME2, EXCHANGE_NAME, "error.#");
        channel.queueBind(QUEUE_NAME2, EXCHANGE_NAME, "info.#");


        for(int i=0;i<10;i++){
            String message = "routing message"+i;
            channel.basicPublish(EXCHANGE_NAME, "info.asddas.adssda", null, message.getBytes());
            channel.basicPublish(EXCHANGE_NAME, "error.dasdas.adsdsa", null, message.getBytes());
            channel.basicPublish(EXCHANGE_NAME, "info.dasda", null, message.getBytes());
        }
    }
}
